package com.example.demo.mapper;

import com.example.demo.entity.Book;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface BookMapper {
    @Select("select * from book order by convert(BookName using gbk) asc")
    List<Book> selectBook();

    @Select("select * from book where BookName like concat('%',#{name},'%') or Author like concat('%',#{name},'%')")
    List<Book> selectByName(String name);

    @Select("select * from book where TypeId=#{type}")
    List<Book> selectByType(int type);

    @Update("update book set BNumber=BNumber-#{number} where BookId=#{id}")
    void updateBNumber(int number,int id);

    @Select("select * from book where BookId=#{id}")
    Book selectById(String id);

    @Update("update book set BNumber=#{BNumber},Summary=#{Summary},Price=#{Price},Publisher=#{Publisher},Author=#{Author},BookName=#{BookName},Img=#{Img},TypeId=#{TypeId} where BookId=#{BookId}")
    void updateBook(Book book);

    @Insert("insert into book(BNumber,Summary,Price,Publisher,Author,BookName,Img,TypeId) values(#{BNumber},#{Summary},#{Price},#{Publisher},#{Author},#{BookName},#{Img},#{TypeId})")
    void addBook(Book book);

    @Delete("delete from book where BookId=#{id}")
    void delBook(String id);

    @Select("select BNumber from book where BookId=#{bookId}")
    int selectBookNB(int bookId);
}
